package com.ych.modules.sql.service.impl;

import com.ych.modules.sql.dao.SysSqlDao;
import com.ych.modules.sql.service.ISysSqlService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Author: Usopp.tsui
 * Date: 2020/12/5
 * Time: 16:37
 * Description:
 */
@Service("ISysSqlService")
public class SysSqlServiceImpl implements ISysSqlService {
    @Autowired
    private SysSqlDao sysSqlDao;
    @Override
    public List<Map<String, Object>> selectSql(String sql) {
        if (StringUtils.isBlank(sql)){
            throw new RuntimeException("sql语句为空");
        }
        if (sql.indexOf("insert ")!=-1||sql.indexOf("update ")!=-1||sql.indexOf("delete ")!=-1){
            throw new RuntimeException("sql语句不能含有insert,update,delete关键字操作");
        }
        return sysSqlDao.selectSql(sql);
    }
}
